package api

import (
	"My_Blog02/middleware"
	"My_Blog02/model"
	"My_Blog02/utils/errmsg"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	account := c.Query("account")
	password := c.Query("password")

	//首先判断账户密码是否正确
	code := model.JudgeAccount(account, password)
	if code == errmsg.ERROR_NOT_FOUND {
		c.JSON(200, gin.H{
			"code":    code,
			"message": errmsg.GetMsg(code),
			"data":    "",
		})
		return
	}
	var token string
	if code == errmsg.SUCCSE {
		token, code = middleware.SetToken(account)
	}
	c.JSON(200, gin.H{
		"code":    code,
		"message": errmsg.GetMsg(code),
		"data":    token,
	})
}
